#include <fstream>
using namespace std;
ofstream out("order.out");

#define CLASS(ID) class ID{ \
   public: \
   ID(int) { out << #ID " constuctor\n";} \
   ~ID(){out << #ID " destuctor\n";} \
};

CLASS(Base1);
CLASS(Member1);
CLASS(Member2);
CLASS(Member3);
CLASS(Member4);

class Derived1: public Base1{
    Member1 m1;
    Member2 m2;
public:
    Derived1(int):m2(1),m1(2),Base1(3){
        out<< "Derived1 constuctor\n";
    }  
    ~Derived1(){
        out<< "Derived1 destuctor\n";
    }   
};

class Derived2: public Derived1{
    Member3 m3;
    Member4 m4;
public:
    Derived2():m3(1),m4(3),Derived1(2){
        out<< "Derived2 constuctor\n";
    }  
    ~Derived2(){
        out<< "Derived2 destuctor\n";
    }   
};   //构造函数是从类层次的最根处开始，而在每一层，首先会调用基类构造函数，然后调用成员对象构造函数。析构函数则相反。


int main(){
    Derived2 d2;
}
